package com.hamster.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hamster.crm.pojo.Opinionaire;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 问卷调查的 mapper
 * @author Tarry
 * @create 2019/12/23 11:21
 */
@Repository
@Mapper
public interface OpinionaireMapper extends BaseMapper<Opinionaire> {

    /**
     * 根据id，逻辑删除
     * @param id
     */
    @Update("update opinionaire set del = 1 where id = #{id}")
    void deleteTag(String id);

    /**
     * 根据id修改状态为“已下发”
     * @param id
     */
    @Update("update opinionaire set state = #{state} where id = #{id}")
    void updateOpinionaireStateById(@Param("id") String id, @Param("state") String state);

    @Select("select * from opinionaire where del = 0  order by create_time desc")
    @Results({
            @Result(property = "id",column = "id",id = true),
            @Result(property = "title",column = "title"),
            @Result(property = "content",column = "content"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "state",column = "state",one = @One(select = "com.hamster.crm.mapper.OpinionaireMapper.selectStateById")),
    })
    List<Opinionaire> selectOpinionaireList();

    @Select("select state from  dictionary_state where id = #{id}")
    String selectStateById(@Param("id") String id);
}
